<?php
declare (strict_types = 1);

namespace app\admin\model;

use think\Model;
use app\admin\model\Sku;
use think\facade\Db;

/**
 * @mixin \think\Model
 */
class Product extends Model
{
    protected $schema = [
        'id' => 'int',
        'name' => 'string',
        'avatar' => 'string',
        'material' => 'string',
        'manufacturer' => 'string',
        'shop_no' => 'string',
        'create_time' => 'int',
    ];

    public function sku() {
        return $this->hasMany(Sku::class, 'product_id', 'id');
    }

    public function delProduct($ids)
    {
        return Product::destroy($ids);
    }

    public function getProductJoinSku()
    {
        $result = Db::table('lm_product')
        ->alias('p')
        ->join('lm_sku s', 'p.id = s.product_id', 'LEFT')
        ->select()->toArray();
        halt($result);
        return $result;
    }
}
